home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / mus / play / multiplsr.lha / rexx.asm < prev    next >
Assembly Source File  |  1992-09-14  |  11KB  |  390 lines

  1. * MultiPlayer
  2. * Copyright (C) 1992 Bryan Ford
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. *
  18. * I (the author of MultiPlayer) can be contacted on the Internet at
  19. * "bryan.ford@m.cc.utah.edu".  See "Player.doc" for other addresses.
  20. *
  21. * $Id: rexx.asm,v 5.1 92/09/14 18:39:35 BAF Exp $
  22. *
  23.  
  24.         include "exec/types.i"
  25.         include "exec/funcdef.i"
  26.         include "exec/exec_lib.i"
  27.         include "dos/dos.i"
  28.         include "rexx/storage.i"
  29.         include "rexx/rxslib.i"
  30.         include "bry/macros.i"
  31.         include "bry/remind.i"
  32.         include "player.i"
  33.  
  34. rxcmd   macro   ; name,len
  35.         dc.l    \1text
  36.         dc.w    rexx\1-5$
  37.         dc.w    \2
  38.         endm
  39.  
  40.         xref    _remind_rem
  41.         xref    _addcalls,loadmod,playmod,startmod,stopmod,endmod,contmod
  42.         xref    _SysBase,_sysflags,_procpt,nocontinue
  43.         xref    _windowopen,_windowclose
  44.  
  45.         xdef    _initrexx
  46.  
  47.         code    text
  48.  
  49. *** quotok - Call ARexx's StcToken, but "lose" any quotes around the string
  50. * a0 = string
  51. * a6 = rxbase
  52. * Returns: Same as _LVOStcToken, except CCR = D1
  53. quotok:
  54.         jsr     _LVOStcToken(a6)
  55.  
  56.         tst.l   d1                      ; Check for a zero string
  57.         beq.s   9$
  58.  
  59.         cmp.b   (a1),d0                 ; Check for initial quote
  60.         bne.s   5$
  61.         addq.l  #1,a1
  62.         subq.l  #1,d1
  63.         beq.s   9$
  64. 5$
  65.         cmp.b   -1(a1,d1.l),d0          ; Check for ending quote
  66.         bne.s   9$
  67.         subq.l  #1,d1
  68.  
  69. 9$      rts
  70.  
  71. *** argquotok - Calls quotok, but converts the token into an Argstring
  72. * a0 = string
  73. * a6 = rxbase
  74. * d7 = checkrexx's return SP
  75. * Returns: a0 = argstring, a1 = scan
  76. * NOTE: Returns through the stack if out of memory
  77. argquotok:
  78.         bsr     freearg                 ; Free up a rxarg slot
  79.  
  80.         bsr     quotok                  ; Get the next token
  81.  
  82.         move.l  a0,-(sp)                ; Create the Argstring
  83.         move.l  a1,a0
  84.         move.l  d1,d0
  85.         jsr     _LVOCreateArgstring(a6)
  86.         move.l  a0,rxarg(a4)
  87.         beq.s   99$
  88.  
  89.         move.l  (sp)+,a1
  90.         rts
  91.  
  92. 99$     lea     nomem(a4),a0            ; Return an error directly
  93.         move.l  a0,d0
  94.         ; fall through...
  95. *** rexxerr - Generate an ARexx error message
  96. * d0 = Error message or NULL if OK
  97. * d7 = checkrexx's return SP
  98. rexxerr:
  99.         move.l  d7,sp                   ; Return straight to checkrexx
  100.  
  101.         tst.l   d0                      ; Check the error
  102.         beq.s   9$
  103.         move.l  d0,rxerr(a4)
  104.         moveq   #10,d0
  105.  
  106. 9$      rts
  107.  
  108. *** _initrexx - Initialize the ARexx message port and system
  109. _initrexx:
  110.         move.l  a6,-(sp)
  111.  
  112.         lea     endnode(a4),a0          ; Add the callnodes
  113.         lea     endrexx(pc),a1
  114.         move.l  a1,rn_callfunc(a0)
  115.         move.l  a0,-(sp)
  116.         clr.l   -(sp)
  117.         clr.l   -(sp)
  118.         lea     checknode(a4),a0
  119.         lea     checkrexx(pc),a1
  120.         move.l  a1,rn_callfunc(a0)
  121.         move.l  a0,-(sp)
  122.         jsr     _addcalls
  123.         lea     4*4(sp),sp
  124.  
  125.         move.l  _SysBase(a4),a6         ; Open rexxsyslib
  126.         lea     rxname(a4),a1
  127.         moveq   #0,d0
  128.         jsr     _LVOOpenLibrary(a6)
  129.         move.l  d0,rxbase(a4)
  130.         beq     9$
  131.  
  132.         lea     rxport(a4),a1           ; Add MsgPort to system list
  133.         move.l  _procpt(a4),MP_SIGTASK(a1)
  134.         jsr     _LVOAddPort(a6)
  135.  
  136. 9$      move.l  (sp)+,a6
  137.         rts
  138.  
  139. *** freearg - Free any currently allocated rxarg
  140. * Returns: a0 = preserved
  141. freearg:
  142.         move.l  rxarg(a4),d0
  143.         beq.s   9$
  144.         movem.l a0/a6,-(sp)
  145.         move.l  d0,a0
  146.         move.l  rxbase(a4),a6
  147.         jsr     _LVODeleteArgstring(a6)
  148.         movem.l (sp)+,a0/a6
  149.         clr.l   rxarg(a4)
  150. 9$      rts
  151.  
  152. *** endrexx - Close the ARexx port and free everything
  153. * Returns: d0 = Overlay handle to unlock
  154. endrexx:
  155.         tst.l   rxbase(a4)              ; See if we ever opened successfully
  156.         bz      9$
  157.  
  158.         bsr     freearg                 ; Free any curently allocated rxarg
  159.  
  160.         move.l  a6,-(sp)
  161.  
  162.         move.l  _SysBase(a4),a6
  163.         jsr     _LVOForbid(a6)
  164.  
  165. 1$      lea     rxport(a4),a0           ; Get rid of all dead messages
  166.         jsr     _LVOGetMsg(a6)
  167.         tst.l   d0
  168.         beq.s   19$
  169.         move.l  d0,a1
  170.         moveq   #20,d0
  171.         move.l  d0,rm_Result1(a1)
  172.         clr.l   rm_Result2(a1)
  173.         jsr     _LVOReplyMsg(a6)
  174.         bra.s   1$
  175. 19$
  176.         lea     rxport(a4),a1           ; Remove the message port
  177.         jsr     _LVORemPort(a6)
  178.  
  179.         jsr     _LVOPermit(a6)
  180.  
  181.         move.l  rxbase(a4),a1           ; Close the library
  182.         clr.l   rxbase(a4)
  183.         jsr     _LVOCloseLibrary(a6)
  184.  
  185.         move.l  (sp)+,a6
  186.  
  187. 9$      pea     checknode(a4)           ; Remove the callnodes
  188.         jsr     _remind_rem
  189.         pea     endnode(a4)
  190.         jsr     _remind_rem
  191.         addq    #8,sp
  192.  
  193.         rts
  194.  
  195. *** rexxload - Load a module without playing it
  196. rexxload:
  197.         bsr     quotok                  ; Find the filename
  198.  
  199.         move.l  a1,a0                   ; Load the module
  200.         bsr     loadmod
  201.  
  202.         bra     rexxerr
  203.  
  204. *** rexxplay - Play a loaded or not-yet-loaded module
  205. rexxplay:
  206.         bsr     argquotok               ; Find the filename or song number
  207.         tst.l   d1
  208.         beq.s   5$
  209.  
  210.         movem.l a0/a1,-(sp)             ; See if it's a number
  211.         jsr     _LVOCVa2i(a6)
  212.         tst.l   d1
  213.         bne.s   5$
  214.  
  215.         move.l  (sp)+,a0                ; Load the file
  216.         bsr     loadmod
  217.         tst.l   d0
  218.         bne     rexxerr
  219.  
  220.         move.l  (sp)+,a0                ; Find second token
  221.         bsr     argquotok
  222.  
  223.         jsr     _LVOCVa2i(a6)           ; Maybe *this* one's a number
  224.  
  225. 5$      ;move.l d1,d0                   ; Start playing the module
  226.         bsr     playmod
  227.  
  228.         bra     rexxerr
  229.  
  230. *** rexxstop - Stop a currently playing module
  231. rexxstop:
  232.         bra     stopmod
  233.  
  234. *** rexxeject, rexxunload - Unload any module in memory
  235. rexxeject:
  236. rexxunload:
  237.         bra     endmod
  238.  
  239. *** rexxcontinue - Continue module, called from rexx.a
  240. rexxcontinue:
  241.         bsr     contmod                 ; Try to continue the module
  242.  
  243.         tst.l   d0                      ; See if it was successful
  244.         beq     rexxerr
  245.         move.l  d0,rxerr(a4)
  246.  
  247.         lea     nocontinue(a4),a0       ; See if it couldn't continue
  248.         cmp.l   a0,d0
  249.         bne     rexxerr
  250.  
  251.         moveq   #5,d0                   ; Special error - returncode 5
  252.         rts
  253.  
  254. *** rexxlasterror - Return the last error message in rm_Result2
  255. rexxlasterror:
  256.         move.l  rxerr(a4),a0            ; Create an Argstring for the error
  257.         jsr     _LVOStrlen(a6)
  258.         jsr     _LVOCreateArgstring(a6)
  259.         beq.s   9$
  260.         move.l  d0,rm_Result2(a2)
  261.  
  262.         moveq   #0,d0
  263.         move.l  (sp)+,a0                ; Return to after the clr instruction
  264.         addq.l  #4,a0
  265.         jmp     (a0)
  266.  
  267. 9$      moveq   #20,d0                  ; Big trouble!
  268.         rts
  269.  
  270. *** rexxquit - Quit MultiPlayer
  271. rexxquit:
  272.         bset    #SB_KILL,_sysflags(a4)
  273.         rts
  274.  
  275. *** rexxopenwin - Open the MultiPlayer window
  276. rexxopenwin:
  277.         pea     rexxerr(pc)
  278.         jmp     _windowopen
  279.  
  280. *** rexxclosewin - Close the MultiPlayer window
  281. rexxclosewin:
  282.         jsr     _windowclose
  283.         moveq   #0,d0
  284.         rts
  285.  
  286. *** chexkrexx - Check for incoming ARexx messages
  287. * Returns null
  288. checkrexx:
  289.         tst.l   rxbase(a4)              ; See if we ever opened successfully
  290.         beq     99$
  291.  
  292.         movem.l d2-d5/d7/a2-a3/a6,-(sp)
  293.  
  294. 1$      lea     rxport(a4),a0           ; Find the next message (a2)
  295.         move.l  _SysBase(a4),a6
  296.         jsr     _LVOGetMsg(a6)
  297.         tst.l   d0
  298.         bz.s    9$
  299.         move.l  d0,a2
  300.  
  301.         move.l  rxbase(a4),a6           ; Find the command name
  302.         move.l  rm_Args(a2),a0
  303.         bsr     quotok
  304.         move.l  a1,d2
  305.         move.l  d1,d3
  306.         move.l  a0,d4
  307.  
  308.         lea     59$(pc),a3              ; Search through command table
  309. 2$      move.l  (a3)+,d0
  310.         beq.s   81$
  311.         move.w  (a3)+,d5
  312.         cmp.w   (a3)+,d3
  313.         bne.s   2$
  314.         move.l  d0,a0
  315.         move.l  d2,a1
  316.         move.l  d3,d0
  317.         jsr     _LVOStrcmpN(a6)
  318.         bne.s   2$
  319.  
  320.         move.l  sp,d7                   ; Place to return to on errors
  321.         subq.l  #4,d7
  322.  
  323.         move.l  d4,a0                   ; Call the appropriate routine
  324. 5$      jsr     -2(pc,d5.w)
  325.  
  326. 6$      clr.l   rm_Result2(a2)          ; Set the returncodes
  327.         move.l  d0,rm_Result1(a2)       ; NOTE: First clr skipped by rexxlasterror!
  328.  
  329.         move.l  _SysBase(a4),a6         ; Return the message
  330.         move.l  a2,a1
  331.         jsr     _LVOReplyMsg(a6)
  332.  
  333.         bra     1$                      ; Back for more
  334.  
  335. 9$      movem.l (sp)+,d2-d5/d7/a2-a3/a6
  336. 99$     cq      d0
  337.         rts
  338.  
  339. 81$     moveq   #10,d0
  340.         bra     6$
  341.  
  342. 59$     rxcmd   load,4                  ; Command table
  343.         rxcmd   play,4
  344.         rxcmd   stop,4
  345.         rxcmd   eject,5
  346.         rxcmd   unload,6
  347.         rxcmd   continue,8
  348.         rxcmd   quit,4
  349.         rxcmd   lasterror,9
  350.         rxcmd   openwin,11
  351.         rxcmd   closewin,12
  352.         dc.l    0
  353.  
  354.         data    __MERGED
  355.  
  356. rxport  dc.l    0,0
  357.         dc.b    NT_MSGPORT,0
  358.         dc.l    rxportname
  359.         dc.b    PA_SIGNAL,SIGBREAKB_CTRL_E
  360.         dc.l    0
  361. 1$      dc.l    2$
  362. 2$      dc.l    0
  363.         dc.l    1$
  364.  
  365. rxname          dc.b    "rexxsyslib.library",0
  366. rxportname      dc.b    "RXTRACKER",0
  367. nomem           dc.b    "Not enough memory",0
  368.  
  369. loadtext        dc.b    "LOAD"
  370. playtext        dc.b    "PLAY"
  371. stoptext        dc.b    "STOP"
  372. ejecttext       dc.b    "EJECT"
  373. unloadtext      dc.b    "UNLOAD"
  374. continuetext    dc.b    "CONTINUE"
  375. quittext        dc.b    "QUIT"
  376. lasterrortext   dc.b    "LASTERROR"
  377. openwintext     dc.b    "OPENWINDOWS"
  378. closewintext    dc.b    "CLOSEWINDOWS"
  379.  
  380.         bss     __MERGED
  381.  
  382. rxbase          ds.l    1                       ; rexxsyslib base
  383. rxerr           ds.l    1                       ; Last error message
  384. rxarg           ds.l    1                       ; Currently allocated argstring
  385.  
  386. checknode       ds.b    rn_SIZEOF               ; CallNodes
  387. endnode         ds.b    rn_SIZEOF
  388.  
  389.         end
  390.